From f99e0aba70efad0deb907d8e27f09fc9f527c8a4 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 17 Feb 2023 17:07:50 +0700 Subject: Refactor --- src2/pages/my/invoice/[id].js | 149 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 src2/pages/my/invoice/[id].js (limited to 'src2/pages/my/invoice/[id].js') diff --git a/src2/pages/my/invoice/[id].js b/src2/pages/my/invoice/[id].js new file mode 100644 index 00000000..820c9af8 --- /dev/null +++ b/src2/pages/my/invoice/[id].js @@ -0,0 +1,149 @@ +import AppBar from "@/components/layouts/AppBar"; +import Layout from "@/components/layouts/Layout"; +import LineDivider from "@/components/elements/LineDivider"; +import WithAuth from "@/components/auth/WithAuth"; +import { useEffect, useState } from "react"; +import apiOdoo from "@/core/utils/apiOdoo"; +import { useRouter } from "next/router"; +import { useAuth } from "@/core/utils/auth"; +import VariantCard from "@/components/variants/VariantCard"; +import currencyFormat from "@/core/utils/currencyFormat"; +import Disclosure from "@/components/elements/Disclosure"; +import DescriptionRow from "@/components/elements/DescriptionRow"; +import { SkeletonList } from "@/components/elements/Skeleton"; +import VariantGroupCard from "@/components/variants/VariantGroupCard"; + +export default function DetailInvoice() { + const router = useRouter(); + const { id } = router.query; + const [ auth ] = useAuth(); + const [ invoice, setInvoice ] = useState(null); + + useEffect(() => { + if (auth && id) { + const loadInvoice = async () => { + const dataInvoice = await apiOdoo('GET', `/api/v1/partner/${auth?.partner_id}/invoice/${id}`); + setInvoice(dataInvoice); + } + loadInvoice(); + } + }, [ auth, id ]); + + const Customer = () => { + const customer = invoice?.customer; + const fullAddress = []; + if (customer?.street) fullAddress.push(customer.street); + if (customer?.sub_district?.name) fullAddress.push(customer.sub_district.name); + if (customer?.district?.name) fullAddress.push(customer.district.name); + if (customer?.city?.name) fullAddress.push(customer.city.name); + + return ( +
+ { invoice?.customer?.name } + { invoice?.customer?.email || '-' } + { invoice?.customer?.mobile || '-' } + { fullAddress.join(', ') } +
+ ); + }; + + const downloadTaxInvoice = () => { + window.open(`${process.env.ODOO_HOST}/api/v1/download/tax-invoice/${invoice.id}/${invoice.token}`, 'Download') + } + + const downloadInvoice = () => { + window.open(`${process.env.ODOO_HOST}/api/v1/download/invoice/${invoice.id}/${invoice.token}`, 'Download') + } + + return ( + + + + + { invoice ? ( + <> +
+ + { invoice?.name } + + + { invoice?.amount_residual > 0 ? ( + Belum Lunas + ) : ( + Lunas + ) } + + + { invoice?.purchase_order_name || '-' } + + + { invoice?.payment_term } + + { invoice?.amount_residual > 0 && invoice.invoice_date != invoice.invoice_date_due && ( + + { invoice?.invoice_date_due } + + ) } + + { invoice?.sales } + + + { invoice?.invoice_date } + +
+

Faktur Pembelian

+ +
+
+

Faktur Pajak

+ +
+
+ + + + + + + + + + + +
+ +
+

Total Belanja

+

{ currencyFormat(invoice?.amount_total || 0) }

+
+
+ + ) : ( +
+ +
+ ) } +
+
+ ); +} \ No newline at end of file -- cgit v1.2.3